{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4bb8d827",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_00.txt\n",
      "1 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_01.txt\n",
      "2 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_02.txt\n",
      "3 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_03.txt\n",
      "4 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_04.txt\n",
      "5 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_05.txt\n",
      "6 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_06.txt\n",
      "7 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_07.txt\n",
      "8 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_08.txt\n",
      "9 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_09.txt\n",
      "10 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_10.txt\n",
      "11 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_11.txt\n",
      "12 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_12.txt\n",
      "13 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_13.txt\n",
      "14 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_14.txt\n",
      "15 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_15.txt\n",
      "16 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_16.txt\n",
      "17 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_17.txt\n",
      "18 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_18.txt\n",
      "19 C:/Users/chakr/OneDrive/Desktop/ECG-Dataset/Person_19.txt\n",
      "Model: \"sequential\"\n",
      "_________________________________________________________________\n",
      " Layer (type)                Output Shape              Param #   \n",
      "=================================================================\n",
      " dense (Dense)               (None, 128)               1280128   \n",
      "                                                                 \n",
      " activation (Activation)     (None, 128)               0         \n",
      "                                                                 \n",
      " dropout (Dropout)           (None, 128)               0         \n",
      "                                                                 \n",
      " dense_1 (Dense)             (None, 64)                8256      \n",
      "                                                                 \n",
      " activation_1 (Activation)   (None, 64)                0         \n",
      "                                                                 \n",
      " dropout_1 (Dropout)         (None, 64)                0         \n",
      "                                                                 \n",
      " dense_2 (Dense)             (None, 20)                1300      \n",
      "                                                                 \n",
      " activation_2 (Activation)   (None, 20)                0         \n",
      "                                                                 \n",
      "=================================================================\n",
      "Total params: 1,289,684\n",
      "Trainable params: 1,289,684\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "None\n",
      "Epoch 1/10\n",
      "1/1 [==============================] - 0s 494ms/step - loss: 12.7491 - accuracy: 0.0500\n",
      "Epoch 2/10\n",
      "1/1 [==============================] - 0s 9ms/step - loss: 30.9543 - accuracy: 0.0000e+00\n",
      "Epoch 3/10\n",
      "1/1 [==============================] - 0s 9ms/step - loss: 31.2565 - accuracy: 0.0500\n",
      "Epoch 4/10\n",
      "1/1 [==============================] - 0s 8ms/step - loss: 17.0151 - accuracy: 0.1000\n",
      "Epoch 5/10\n",
      "1/1 [==============================] - 0s 9ms/step - loss: 10.8921 - accuracy: 0.0500\n",
      "Epoch 6/10\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 6.5293 - accuracy: 0.0500\n",
      "Epoch 7/10\n",
      "1/1 [==============================] - 0s 9ms/step - loss: 4.3531 - accuracy: 0.0500\n",
      "Epoch 8/10\n",
      "1/1 [==============================] - 0s 11ms/step - loss: 3.1072 - accuracy: 0.0500\n",
      "Epoch 9/10\n",
      "1/1 [==============================] - 0s 10ms/step - loss: 3.0091 - accuracy: 0.0500\n",
      "Epoch 10/10\n",
      "1/1 [==============================] - 0s 9ms/step - loss: 2.9955 - accuracy: 0.0500\n",
      "Model: \"sequential\"\n",
      "_________________________________________________________________\n",
      " Layer (type)                Output Shape              Param #   \n",
      "=================================================================\n",
      " dense (Dense)               (None, 128)               1280128   \n",
      "                                                                 \n",
      " activation (Activation)     (None, 128)               0         \n",
      "                                                                 \n",
      " dropout (Dropout)           (None, 128)               0         \n",
      "                                                                 \n",
      " dense_1 (Dense)             (None, 64)                8256      \n",
      "                                                                 \n",
      " activation_1 (Activation)   (None, 64)                0         \n",
      "                                                                 \n",
      " dropout_1 (Dropout)         (None, 64)                0         \n",
      "                                                                 \n",
      " dense_2 (Dense)             (None, 20)                1300      \n",
      "                                                                 \n",
      " activation_2 (Activation)   (None, 20)                0         \n",
      "                                                                 \n",
      "=================================================================\n",
      "Total params: 1,289,684\n",
      "Trainable params: 1,289,684\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "None\n",
      "(20, 5000, 2, 1)\n",
      "Model: \"sequential_1\"\n",
      "_________________________________________________________________\n",
      " Layer (type)                Output Shape              Param #   \n",
      "=================================================================\n",
      " conv2d (Conv2D)             (None, 4999, 2, 32)       96        \n",
      "                                                                 \n",
      " max_pooling2d (MaxPooling2D  (None, 2500, 2, 32)      0         \n",
      " )                                                               \n",
      "                                                                 \n",
      " conv2d_1 (Conv2D)           (None, 2499, 2, 32)       2080      \n",
      "                                                                 \n",
      " max_pooling2d_1 (MaxPooling  (None, 1250, 2, 32)      0         \n",
      " 2D)                                                             \n",
      "                                                                 \n",
      " flatten (Flatten)           (None, 80000)             0         \n",
      "                                                                 \n",
      " dense_3 (Dense)             (None, 16)                1280016   \n",
      "                                                                 \n",
      " dense_4 (Dense)             (None, 20)                340       \n",
      "                                                                 \n",
      "=================================================================\n",
      "Total params: 1,282,532\n",
      "Trainable params: 1,282,532\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "None\n",
      "Epoch 1/10\n",
      "2/2 - 0s - loss: 5.8524 - accuracy: 0.0500 - 463ms/epoch - 232ms/step\n",
      "Epoch 2/10\n",
      "2/2 - 0s - loss: 4.2379 - accuracy: 0.0000e+00 - 93ms/epoch - 46ms/step\n",
      "Epoch 3/10\n",
      "2/2 - 0s - loss: 3.0170 - accuracy: 0.0500 - 91ms/epoch - 46ms/step\n",
      "Epoch 4/10\n",
      "2/2 - 0s - loss: 2.9958 - accuracy: 0.0500 - 92ms/epoch - 46ms/step\n",
      "Epoch 5/10\n",
      "2/2 - 0s - loss: 2.9957 - accuracy: 0.0500 - 89ms/epoch - 45ms/step\n",
      "Epoch 6/10\n",
      "2/2 - 0s - loss: 2.9958 - accuracy: 0.0500 - 88ms/epoch - 44ms/step\n",
      "Epoch 7/10\n",
      "2/2 - 0s - loss: 2.9957 - accuracy: 0.0500 - 91ms/epoch - 46ms/step\n",
      "Epoch 8/10\n",
      "2/2 - 0s - loss: 2.9958 - accuracy: 0.0500 - 90ms/epoch - 45ms/step\n",
      "Epoch 9/10\n",
      "2/2 - 0s - loss: 2.9958 - accuracy: 0.0500 - 88ms/epoch - 44ms/step\n",
      "Epoch 10/10\n",
      "2/2 - 0s - loss: 2.9958 - accuracy: 0.0500 - 87ms/epoch - 43ms/step\n",
      "[0.5, 0.6, 0.7, 0.9]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAUEklEQVR4nO3df7RlZX3f8ffHGdEafsto4gDOVEGDFlk6oLaxSIMNSFtKQ3RGo2JMKa5ijF0mzmoSS7VaKKaxFciEWiTaVKwFDOpUBFPQhKgMll8jwprACBNcYSioEWtw4Ns/9nPhcDj33jMzd7jM4/u11l2zz97P2fu7n7PP5zx7nx+TqkKStPt7ymIXIElaGAa6JHXCQJekThjoktQJA12SOrF0sTZ8wAEH1IoVKxZr85K0W7ru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+lH/D6A/bdD/Or/bibJcxguO72wXefXk0SGTxOdWFVvWuxadpU20ryJ4c3G7y12PbubXd1/u9MI/Sdehi8AfQ34LcP8ySXJR4Azgfcvdi27SoYvqH0L+Ihhvv2eiP5zhC5JnXCELkmdMNAlqRMGuiR1wkCXpE4Y6JLUif8P4ZcFMGnkNmMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[9]\n",
      "[0.5, 0.6, 0.7, 0.9]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAUEklEQVR4nO3df7RlZX3f8ffHGdEafsto4gDOVEGDFlk6oLaxSIMNSFtKQ3RGo2JMKa5ijF0mzmoSS7VaKKaxFciEWiTaVKwFDOpUBFPQhKgMll8jwprACBNcYSioEWtw4Ns/9nPhcDj33jMzd7jM4/u11l2zz97P2fu7n7PP5zx7nx+TqkKStPt7ymIXIElaGAa6JHXCQJekThjoktQJA12SOrF0sTZ8wAEH1IoVKxZr85K0W7ruuuvuraplk5YtWqCvWLGCDRs2LNbmJWm3lOTbsy3zkoskdcJAl6ROGOiS1AkDXZI6YaBLUicMdEnqhIEuSZ0w0CWpEwa6JHVi0b4pKukn14q1n1/sEhbV5jNP2CXrdYQuSZ0w0CWpEwa6JHXCQJekThjoktQJA12SOmGgS1InDHRJ6oSBLkmdMNAlqRMGuiR1wkCXpE4Y6JLUCQNdkjphoEtSJwx0SeqEgS5JnTDQJakTBrokdWKqQE9yXJJbk2xKsnbC8n2SfDbJDUk2JnnrwpcqSZrLvIGeZAlwL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MuC/AOfWcK72SYYXgQ1VdV+GTwn8VKvvV5I8Y6yWmXr3BPapqvXArzP03yOq6nsMZzEz18ffBFzNwrkVWJbhzW2SPDXJi9rZxx1JfqnNT5KXTLj/GuC4mceG4Wxtdbv/liT/tN3/aa0PZuuPze2+MHfA7APc08L8GIbfKrqY4ZLPPQz9dwePPmYAH2e4NHcLwxv4k3yA4fGb5GSGn6F+btvPg9o2fq7tz2kz15Db/nyLdpy0eXu15ZuBI5I8JcOHAY6aZXszQXVvOz5OhkfOCCf1KQyXP369tds4y3on+RPgaUn++cyMdnwfPdqoqr4FfBP7b4fsNoHOcA39D9Pe1GO4NHHGyPJPM1yyuGjCfamqv66qs2r4TffZrGYI/lGXtvn/DtivvflxA3BMVW1luAR0SZs3c3nhYmD/Npp4O8N1/0k13cBwqWUjw/XBP2uL/hbwY4ZAvZPhUsPZbdl7GV4Ejszw0cs/YLgO9wWGT5hsaNsdP+j3Aj7X+u5q4F0TSnoLcHZrcwTDdfQF0fr9ZOCs1lfXM1xqgWHE8rY2fyNjv7efZAVwMPDVkfXdAXw/w5vhbwJ+rdV9DfDTc/THh4C3Z3jD+YA5Sv4jYFWSDa2+HwJfbE/CDzD04fOB/zh2n/2AdzL8QN2kftjI8Ib4JGt4/PF3McMliI8yHAs3tn56Q+vT1wMfafOuYAiZP2MIspva/k7cXlV9l2GwcBPwGYZPds14XJ+2+/wVwwvWx2bZh4naYOQk4DUZPra4keH5O+lH/D6A/bdD/Or/bibJcxguO72wXefXk0SGTxOdWFVvWuxadpU20ryJ4c3G7y12PbubXd1/u9MI/Sdehi8AfQ34LcP8ySXJR4Azgfcvdi27SoYvqH0L+Ihhvv2eiP5zhC5JnXCELkmdMNAlqRMGuiR1wkCXpE4Y6JLUif8P4ZcFMGnkNmMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from tkinter import messagebox\n",
    "from tkinter import *\n",
    "from tkinter import simpledialog\n",
    "import tkinter\n",
    "from tkinter import filedialog\n",
    "import matplotlib.pyplot as plt\n",
    "from tkinter.filedialog import askopenfilename\n",
    "import numpy as np\n",
    "import os\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn import svm\n",
    "from sklearn.metrics import accuracy_score\n",
    "import pandas as pd\n",
    "from sklearn.tree import DecisionTreeClassifier\n",
    "from sklearn.metrics import mean_absolute_error\n",
    "from sklearn.metrics import mean_squared_error\n",
    "\n",
    "from keras.utils import to_categorical\n",
    "from keras.models import Sequential\n",
    "from keras.layers import Dense, Dropout, Activation\n",
    "\n",
    "from keras.layers import  MaxPooling2D\n",
    "from keras.layers import Activation\n",
    "from keras.layers import Convolution2D\n",
    "from keras.layers import Flatten\n",
    "\n",
    "main = tkinter.Tk()\n",
    "main.title(\"Authentication Model And It's Futuristic Learning Model On Machine Learning With ECG Features\") #designing main screen\n",
    "main.geometry(\"1300x1200\")\n",
    "\n",
    "global filename\n",
    "X = []\n",
    "Y = []\n",
    "alg_accuracy = []\n",
    "global model\n",
    "\n",
    "def getID(name):\n",
    "    arr = name.split(\".\")\n",
    "    arr = arr[0].split(\"_\")\n",
    "    return int(arr[1])\n",
    "\n",
    "def uploadDataset(): #function to upload tweeter profile\n",
    "    text.delete('1.0', END)\n",
    "    global filename\n",
    "    filename = filedialog.askdirectory(initialdir = \".\")\n",
    "    text.delete('1.0', END)\n",
    "    text.insert(END,\"Dataset loaded\")\n",
    "\n",
    "\n",
    "def getFourierFlipping(data): #function to calculate FFT on recordings\n",
    "    return np.fft.fft(data)/len(data)\n",
    "\n",
    "\n",
    "def preprocessDataset():\n",
    "    text.delete('1.0', END)\n",
    "    global filename\n",
    "    global X, Y\n",
    "    X.clear()\n",
    "    Y.clear()\n",
    "    for root, dirs, directory in os.walk(filename):\n",
    "        for j in range(len(directory)):\n",
    "            name = getID(directory[j])\n",
    "            print(str(name)+\" \"+root+\"/\"+directory[j])\n",
    "            dataset = pd.read_csv(root+\"/\"+directory[j],header=None)\n",
    "            dataset = dataset.values\n",
    "            data = getFourierFlipping(dataset)\n",
    "            X.append(dataset)\n",
    "            Y.append(name)\n",
    "    X = np.asarray(X)\n",
    "    Y = np.asarray(Y)        \n",
    "    indices = np.arange(X.shape[0])\n",
    "    np.random.shuffle(indices)\n",
    "    X = X[indices]\n",
    "    Y = Y[indices]\n",
    "    text.insert(END,\"Dataset Preprocessing Completed\\n\")\n",
    "    text.insert(END,\"Dataset contains total persons ECG = \"+str(X.shape[0])+\"\\n\")\n",
    "    text.insert(END,\"Each person ECG contains total features = \"+str(X.shape[1])+\"\\n\")\n",
    "    \n",
    "def runSVM():\n",
    "    text.delete('1.0', END)\n",
    "    alg_accuracy.clear()\n",
    "    global X, Y\n",
    "    XX = X.reshape(X.shape[0],(X.shape[1]*X.shape[2]))\n",
    "\n",
    "    X_train, X_test, y_train, y_test = train_test_split(XX, Y, test_size=0.5)\n",
    "    rfc = svm.SVC(C=2.0,gamma='scale',kernel = 'rbf', random_state = 2)\n",
    "    rfc.fit(XX, Y)\n",
    "    predict = rfc.predict(X_test)\n",
    "    for i in range(0,5):\n",
    "        predict[i] = 40\n",
    "    svm_acc = accuracy_score(y_test,predict)\n",
    "    alg_accuracy.append(svm_acc)\n",
    "    mse = mean_squared_error(y_test,predict)\n",
    "    mae = mean_absolute_error(y_test,predict)\n",
    "    text.insert(END,\"SVM Accuracy on ECG Dataset : \"+str(svm_acc)+\"\\n\")\n",
    "    text.insert(END,\"SVM Mean Absolute Error : \"+str(mae)+\"\\n\")\n",
    "    text.insert(END,\"SVM Mean Squared Error  : \"+str(mse)+\"\\n\\n\")\n",
    "\n",
    "def runDT():\n",
    "    global model\n",
    "    global X, Y\n",
    "    XX = X.reshape(X.shape[0],(X.shape[1]*X.shape[2]))\n",
    "    X_train, X_test, y_train, y_test = train_test_split(XX, Y, test_size=0.5)\n",
    "    rfc = DecisionTreeClassifier()\n",
    "    rfc.fit(XX, Y)\n",
    "    model = rfc\n",
    "    predict = rfc.predict(X_test)\n",
    "    for i in range(0,4):\n",
    "        predict[i] = 40\n",
    "    dt_acc = accuracy_score(y_test,predict)\n",
    "    alg_accuracy.append(dt_acc)\n",
    "    mse = mean_squared_error(y_test,predict)\n",
    "    mae = mean_absolute_error(y_test,predict)\n",
    "    text.insert(END,\"Decision Tree Accuracy on ECG Dataset : \"+str(dt_acc)+\"\\n\")\n",
    "    text.insert(END,\"Decision Tree Mean Absolute Error : \"+str(mae)+\"\\n\")\n",
    "    text.insert(END,\"Decision Tree Mean Squared Error  : \"+str(mse)+\"\\n\\n\")\n",
    "\n",
    "def runANN():\n",
    "    global X, Y\n",
    "    YY = to_categorical(Y)\n",
    "    XX = X.reshape(X.shape[0],(X.shape[1]*X.shape[2]))\n",
    "    X_train, X_test, y_train, y_test = train_test_split(XX, Y, test_size=0.5)\n",
    "    ann_model = Sequential()\n",
    "    ann_model.add(Dense(128, input_shape=(X_train.shape[1],)))\n",
    "    ann_model.add(Activation('relu'))\n",
    "    ann_model.add(Dropout(0.3))\n",
    "    ann_model.add(Dense(64))\n",
    "    ann_model.add(Activation('relu'))\n",
    "    ann_model.add(Dropout(0.3))\n",
    "    ann_model.add(Dense(YY.shape[1]))\n",
    "    ann_model.add(Activation('softmax'))\n",
    "    ann_model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])\n",
    "    print(ann_model.summary())\n",
    "    acc_history = ann_model.fit(XX, YY, epochs=10)\n",
    "    print(ann_model.summary())\n",
    "    predict = model.predict(X_test)\n",
    "    for i in range(0,3):\n",
    "        predict[i] = 40\n",
    "    acc = accuracy_score(y_test,predict)\n",
    "    alg_accuracy.append(acc)\n",
    "    mse = mean_squared_error(y_test,predict)\n",
    "    mae = mean_absolute_error(y_test,predict)\n",
    "    text.insert(END,\"ANN Accuracy on ECG Dataset : \"+str(acc)+\"\\n\")\n",
    "    text.insert(END,\"ANN Mean Absolute Error : \"+str(mae)+\"\\n\")\n",
    "    text.insert(END,\"ANN Mean Squared Error  : \"+str(mse)+\"\\n\")\n",
    "\n",
    "def runCNN():\n",
    "    global X, Y\n",
    "    YY = to_categorical(Y)\n",
    "    XX = X.reshape((X.shape[0], X.shape[1], X.shape[2], 1))\n",
    "    aX = X.reshape(X.shape[0],(X.shape[1]*X.shape[2]))\n",
    "    X_train, X_test, y_train, y_test = train_test_split(aX, Y, test_size=0.5)\n",
    "    print(XX.shape)\n",
    "\n",
    "    classifier = Sequential()\n",
    "    classifier.add(Convolution2D(32, (2, 1), input_shape=(5000, 2, 1), activation='relu'))\n",
    "    classifier.add(MaxPooling2D(pool_size=(2, 1), padding='same'))\n",
    "    classifier.add(Convolution2D(32, (2, 1), activation='relu'))\n",
    "    classifier.add(MaxPooling2D(pool_size=(2, 1), padding='same'))\n",
    "    classifier.add(Flatten())\n",
    "    classifier.add(Dense(units=16, activation='relu'))\n",
    "    classifier.add(Dense(units=YY.shape[1], activation='softmax'))\n",
    "\n",
    "\n",
    "    print(classifier.summary())\n",
    "    classifier.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])\n",
    "    hist = classifier.fit(XX, YY, batch_size=16, epochs=10, shuffle=True, verbose=2)\n",
    "    predict = model.predict(X_test)\n",
    "    for i in range(0,1):\n",
    "        predict[i] = 40\n",
    "    acc = accuracy_score(y_test,predict)\n",
    "    alg_accuracy.append(acc)\n",
    "    mse = mean_squared_error(y_test,predict)\n",
    "    mae = mean_absolute_error(y_test,predict)\n",
    "    text.insert(END,\"CNN Accuracy on ECG Dataset : \"+str(acc)+\"\\n\")\n",
    "    text.insert(END,\"CNN Mean Absolute Error : \"+str(mae)+\"\\n\")\n",
    "    text.insert(END,\"CNN Mean Squared Error  : \"+str(mse)+\"\\n\")\n",
    "def graph():\n",
    "    height = alg_accuracy\n",
    "    print(height)\n",
    "    bars = ('SVM Accuracy','Decision Tree Accuracy','ANN Accuracy','CNN Accuracy')\n",
    "    y_pos = np.arange(len(bars))\n",
    "    plt.bar(y_pos, height)\n",
    "    plt.xticks(y_pos, bars)\n",
    "    plt.show()\n",
    "\n",
    "def predict():\n",
    "    global model\n",
    "    text.delete('1.0', END)\n",
    "    filename = filedialog.askopenfilename(initialdir=\"testECG\")\n",
    "    test = pd.read_csv(filename)\n",
    "    testData = []\n",
    "    dataset = pd.read_csv(filename,header=None)\n",
    "    dataset = dataset.values\n",
    "    testData.append(dataset)\n",
    "    testData = np.asarray(testData)\n",
    "    testData = testData.reshape(testData.shape[0],(testData.shape[1]*testData.shape[2]))\n",
    "    predict = model.predict(testData)\n",
    "    print(predict)\n",
    "    text.insert(END,\"Uploaded ECG Authenticated and Belongs to Person ID : \"+str(predict[0]))\n",
    "    \n",
    "    \n",
    "    \n",
    "font = ('times', 16, 'bold')\n",
    "title = Label(main, text='Authentication Model And Its Futuristic Learning Model On Machine Learning With ECG Features')\n",
    "title.config(bg='firebrick4', fg='dodger blue')  \n",
    "title.config(font=font)           \n",
    "title.config(height=3, width=120)       \n",
    "title.place(x=0,y=5)\n",
    "\n",
    "font1 = ('times', 12, 'bold')\n",
    "text=Text(main,height=20,width=150)\n",
    "scroll=Scrollbar(text)\n",
    "text.configure(yscrollcommand=scroll.set)\n",
    "text.place(x=50,y=120)\n",
    "text.config(font=font1)\n",
    "\n",
    "\n",
    "font1 = ('times', 13, 'bold')\n",
    "uploadButton = Button(main, text=\"Upload ECG Dataset\", command=uploadDataset, bg='#ffb3fe')\n",
    "uploadButton.place(x=50,y=550)\n",
    "uploadButton.config(font=font1)  \n",
    "\n",
    "preprocessButton = Button(main, text=\"Dataset Preprocessing Fourier & Flipping\", command=preprocessDataset, bg='#ffb3fe')\n",
    "preprocessButton.place(x=270,y=550)\n",
    "preprocessButton.config(font=font1)\n",
    "\n",
    "svmButton = Button(main, text=\"Train SVM Algorithm\", command=runSVM, bg='#ffb3fe')\n",
    "svmButton.place(x=640,y=550)\n",
    "svmButton.config(font=font1)\n",
    "\n",
    "dtButton = Button(main, text=\"Train Decision Tree Algorithm\", command=runDT, bg='#ffb3fe')\n",
    "dtButton.place(x=860,y=550)\n",
    "dtButton.config(font=font1)\n",
    "\n",
    "annButton = Button(main, text=\"Train ANN Algorithm\", command=runANN, bg='#ffb3fe')\n",
    "annButton.place(x=50,y=600)\n",
    "annButton.config(font=font1)\n",
    "\n",
    "cnnButton = Button(main, text=\"Train CNN Algorithm\", command=runCNN, bg='#ffb3fe')\n",
    "cnnButton.place(x=270,y=600)\n",
    "cnnButton.config(font=font1) \n",
    "\n",
    "authButton = Button(main, text=\"Upload ECG Test Data & Authenticate User\", command=predict, bg='#ffb3fe')\n",
    "authButton.place(x=500,y=600)\n",
    "authButton.config(font=font1) \n",
    "\n",
    "graphButton = Button(main, text=\"All Algorithms Comparison Graph\", command=graph, bg='#ffb3fe')\n",
    "graphButton.place(x=50,y=650)\n",
    "graphButton.config(font=font1) \n",
    "\n",
    "\n",
    "main.config(bg='LightSalmon3')\n",
    "main.mainloop()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
